SUBDIRS = .

# stdlib directory
stdlibdir = $(datadir)/re2c/stdlib

# do not add compiler options/warnings here, add them in configure.ac
AM_CXXFLAGS = $(CXXFLAGSDEFAULT)
AM_CXXFLAGS += -DRE2C_STDLIB_DIR='"$(stdlibdir)/"'
if DEBUG
AM_CXXFLAGS += -DRE2C_DEBUG
endif

RE2CFLAGS = -b -W -Wno-match-empty-string --no-generation-date

# binary
bin_PROGRAMS = re2c
noinst_PROGRAMS =

# sources
re2c_HDR = \
	src/constants.h \
	src/codegen/code.h \
	src/codegen/output.h \
	src/codegen/helpers.h \
	src/options/opt.h \
	src/options/symtab.h \
	src/adfa/adfa.h \
	src/cfg/cfg.h \
	src/dfa/closure_leftmost.h \
	src/dfa/closure_posix.h \
	src/dfa/determinization.h \
	src/dfa/dfa.h \
	src/dfa/posix_precedence.h \
	src/dfa/tag_history.h \
	src/dfa/tagver_table.h \
	src/dfa/tcmd.h \
	src/nfa/nfa.h \
	src/encoding/ebcdic.h \
	src/encoding/enc.h \
	src/encoding/range_suffix.h \
	src/encoding/utf8.h \
	src/encoding/utf16.h \
	src/msg/location.h \
	src/msg/msg.h \
	src/msg/ver_to_vernum.h \
	src/msg/warn.h \
	src/regexp/regexp.h \
	src/regexp/rule.h \
	src/regexp/tag.h \
	src/skeleton/mtag_trie.h \
	src/skeleton/path.h \
	src/skeleton/skeleton.h \
	src/parse/ast.h \
	src/parse/input.h \
	src/debug/debug.h \
	src/util/allocator.h \
	src/util/attribute.h \
	src/util/containers.h \
	src/util/check.h \
	src/util/file_utils.h \
	src/util/forbid_copy.h \
	src/util/hash32.h \
	src/util/nowarn_in_bison.h \
	src/util/range.h \
	src/util/string_utils.h \
	src/util/u32lim.h

re2c_SRC = \
	src/codegen/helpers.cc \
	src/codegen/output.cc \
	src/codegen/pass1_analyze.cc \
	src/codegen/pass2_generate.cc \
	src/codegen/pass3_fixup.cc \
	src/codegen/pass4_render.cc \
	src/options/opt.cc \
	src/options/symtab.cc \
	src/nfa/re_to_nfa.cc \
	src/adfa/adfa.cc \
	src/debug/dump_adfa.cc \
	src/debug/dump_cfg.cc \
	src/debug/dump_dfa.cc \
	src/debug/dump_dfa_tree.cc \
	src/debug/dump_interf.cc \
	src/debug/dump_nfa.cc \
	src/cfg/cfg.cc \
	src/cfg/compact.cc \
	src/cfg/dce.cc \
	src/cfg/freeze.cc \
	src/cfg/interfere.cc \
	src/cfg/liveanal.cc \
	src/cfg/normalize.cc \
	src/cfg/optimize.cc \
	src/cfg/rename.cc \
	src/cfg/varalloc.cc \
	src/dfa/closure.cc \
	src/dfa/dead_rules.cc \
	src/dfa/determinization.cc \
	src/dfa/fallback_tags.cc \
	src/dfa/fillpoints.cc \
	src/dfa/find_state.cc \
	src/dfa/minimization.cc \
	src/dfa/tagver_table.cc \
	src/dfa/tcmd.cc \
	src/encoding/ebcdic.cc \
	src/encoding/enc.cc \
	src/encoding/range_suffix.cc \
	src/encoding/utf8.cc \
	src/encoding/utf16.cc \
	src/msg/msg.cc \
	src/msg/warn.cc \
	src/regexp/ast_to_re.cc \
	src/regexp/default_tags.cc \
	src/regexp/fixed_tags.cc \
	src/regexp/nullable.cc \
	src/regexp/regexp.cc \
	src/regexp/split_charset.cc \
	src/skeleton/control_flow.cc \
	src/skeleton/generate_code.cc \
	src/skeleton/generate_data.cc \
	src/skeleton/maxpath.cc \
	src/skeleton/skeleton.cc \
	src/parse/ast.cc \
	src/parse/input.cc \
	src/util/file_utils.cc \
	src/util/string_utils.cc \
	src/util/range.cc
re2c_SOURCES = \
	src/main.cc \
	$(re2c_HDR) \
	$(re2c_SRC)

# autogenerated sources
re2c_GEN_SRC = \
	src/msg/ver_to_vernum.cc \
	src/options/parse_opts.cc \
	src/parse/lexer.cc \
	src/parse/parser.cc \
	src/parse/conf_lexer.cc \
	src/parse/conf_parser.cc
re2c_GEN_HDR = \
	src/parse/parser.h \
	src/parse/conf_parser.h \
	src/parse/lexer.h
re2c_GEN_STX = \
	src/default_syntax_c.h \
	src/default_syntax_d.h \
	src/default_syntax_go.h \
	src/default_syntax_haskell.h \
	src/default_syntax_java.h \
	src/default_syntax_js.h \
	src/default_syntax_ocaml.h \
	src/default_syntax_python.h \
	src/default_syntax_rust.h \
	src/default_syntax_v.h \
	src/default_syntax_zig.h
re2c_GEN = \
	$(re2c_GEN_SRC) \
	$(re2c_GEN_HDR) \
	$(re2c_GEN_STX)
nodist_re2c_SOURCES = \
	$(re2c_GEN) \
	src/msg/help_re2c.cc

# custom rules create headers and must go before normal rules
BUILT_SOURCES = $(re2c_GEN_SRC) $(re2c_GEN_STX)

# bootstrap sources
re2c_BOOT = \
	bootstrap/doc/re2c.1 \
	bootstrap/doc/re2d.1 \
	bootstrap/doc/re2go.1 \
	bootstrap/doc/re2hs.1 \
	bootstrap/doc/re2java.1 \
	bootstrap/doc/re2js.1 \
	bootstrap/doc/re2ocaml.1 \
	bootstrap/doc/re2py.1 \
	bootstrap/doc/re2rust.1 \
	bootstrap/doc/re2v.1 \
	bootstrap/doc/re2zig.1 \
	bootstrap/src/default_syntax_c.h \
	bootstrap/src/default_syntax_d.h \
	bootstrap/src/default_syntax_go.h \
	bootstrap/src/default_syntax_haskell.h \
	bootstrap/src/default_syntax_java.h \
	bootstrap/src/default_syntax_js.h \
	bootstrap/src/default_syntax_ocaml.h \
	bootstrap/src/default_syntax_python.h \
	bootstrap/src/default_syntax_rust.h \
	bootstrap/src/default_syntax_v.h \
	bootstrap/src/default_syntax_zig.h \
	bootstrap/src/msg/help_re2c.cc \
	bootstrap/src/msg/help_re2d.cc \
	bootstrap/src/msg/help_re2go.cc \
	bootstrap/src/msg/help_re2hs.cc \
	bootstrap/src/msg/help_re2java.cc \
	bootstrap/src/msg/help_re2js.cc \
	bootstrap/src/msg/help_re2ocaml.cc \
	bootstrap/src/msg/help_re2py.cc \
	bootstrap/src/msg/help_re2rust.cc \
	bootstrap/src/msg/help_re2v.cc \
	bootstrap/src/msg/help_re2zig.cc \
	bootstrap/src/msg/ver_to_vernum.cc \
	bootstrap/src/options/parse_opts.cc \
	bootstrap/src/parse/lexer.cc \
	bootstrap/src/parse/lexer.h \
	bootstrap/src/parse/parser.cc \
	bootstrap/src/parse/parser.h \
	bootstrap/src/parse/conf_lexer.cc \
	bootstrap/src/parse/conf_parser.h \
	bootstrap/src/parse/conf_parser.cc

# custom sources
re2c_CUSTOM = \
	src/msg/ver_to_vernum.re \
	src/options/parse_opts.re \
	src/parse/lexer.re \
	src/parse/parser.ypp \
	src/parse/conf_lexer.re \
	src/parse/conf_parser.ypp

# docs
# To build the list of examples for all backends, run:
# find examples -regex '.*\.re\|.*\(state\|01_basic\|definitions\)\..*' -printf '\t%p \\\n' | sort
re2c_SRC_DOC_EXT = \
	doc/manual/basics/api/api1.rst_ \
	doc/manual/basics/api/api2_c.rst_ \
	doc/manual/basics/api/api2_d.rst_ \
	doc/manual/basics/api/api2_go.rst_ \
	doc/manual/basics/api/api2_haskell.rst_ \
	doc/manual/basics/api/api2_java.rst_ \
	doc/manual/basics/api/api2_js.rst_ \
	doc/manual/basics/api/api2_ocaml.rst_ \
	doc/manual/basics/api/api2_python.rst_ \
	doc/manual/basics/api/api2_rust.rst_ \
	doc/manual/basics/api/api2_v.rst_ \
	doc/manual/basics/api/api2_zig.rst_ \
	doc/manual/basics/api/api3.rst_ \
	doc/manual/basics/blocks.rst_ \
	doc/manual/basics/directives.rst_ \
	doc/manual/basics/configurations.rst_ \
	doc/manual/basics/regular_expressions.rst_ \
	doc/manual/basics/syntax.rst_ \
	doc/manual/basics/syntax_files.rst_ \
	doc/manual/basics/options/debug.rst_ \
	doc/manual/basics/options/internal.rst_ \
	doc/manual/basics/options/options.rst_ \
	doc/manual/basics/warnings/warnings_general.rst_ \
	doc/manual/basics/warnings/warnings_list.rst_ \
	doc/manual/eof/01_sentinel.rst_ \
	doc/manual/eof/02_bounds_checking.rst_ \
	doc/manual/eof/03_eof_rule.rst_ \
	doc/manual/eof/04_fake_sentinel.rst_ \
	doc/manual/eof/eof.rst_ \
	doc/manual/features/conditions/blocks.rst_ \
	doc/manual/features/conditions/conditions.rst_ \
	doc/manual/features/dot/dot.rst_ \
	doc/manual/features/encodings/encodings.rst_ \
	doc/manual/features/headers/headers.rst_ \
	doc/manual/features/includes/includes.rst_ \
	doc/manual/features/reuse/reuse.rst_ \
	doc/manual/features/skeleton/skeleton.rst_ \
	doc/manual/features/state/state.rst_ \
	doc/manual/features/submatch/submatch_example_mtags.rst_ \
	doc/manual/features/submatch/submatch_example_captures.rst_ \
	doc/manual/features/submatch/submatch_example_stags_fill.rst_ \
	doc/manual/features/submatch/submatch_example_stags.rst_ \
	doc/manual/features/submatch/submatch.rst_ \
	doc/manual/fill/01_fill.rst_ \
	doc/manual/fill/02_fill.rst_ \
	doc/manual/fill/fill.rst_ \
	doc/manual/authors.rst_ \
	doc/manual/intro.rst_ \
	doc/manual/synopsis.rst_ \
	examples/c/01_basic.c \
	examples/c/01_basic.re \
	examples/c/conditions/parse_u32_blocks.re \
	examples/c/conditions/parse_u32_conditions.re \
	examples/c/encodings/unicode_identifier.re \
	examples/c/eof/01_sentinel.re \
	examples/c/eof/02_bounds_checking.re \
	examples/c/eof/03_eof_rule.re \
	examples/c/eof/04_fake_sentinel.re \
	examples/c/eof/05_fake_sentinel_eof_rule.re \
	examples/c/fill/01_fill.re \
	examples/c/fill/02_fill.re \
	examples/c/generic_api/ifstream.re \
	examples/c/headers/header.re \
	examples/c/headers/lexer/state.h \
	examples/c/includes/definitions.h \
	examples/c/includes/include.re \
	examples/c/real_world/cxx98.re \
	examples/c/reuse/braille.re \
	examples/c/reuse/reuse.re \
	examples/c/reuse/usedir.re \
	examples/c/state/push.re \
	examples/c/submatch/01_stags_fill.re \
	examples/c/submatch/01_stags.re \
	examples/c/submatch/02_mtags.re \
	examples/c/submatch/03_captures.re \
	examples/c/submatch/04_posix_captures.re \
	examples/c/submatch/http_rfc7230.re \
	examples/c/submatch/parse_etc_passwd.re \
	examples/c/submatch/parse_options.re \
	examples/c/submatch/parse_records.re \
	examples/c/submatch/uri_rfc3986.re \
	examples/d/01_basic.d \
	examples/d/01_basic.re \
	examples/d/conditions/parse_u32_blocks.re \
	examples/d/conditions/parse_u32_conditions.re \
	examples/d/encodings/unicode_identifier.re \
	examples/d/eof/01_sentinel.re \
	examples/d/eof/02_bounds_checking.re \
	examples/d/eof/03_eof_rule.re \
	examples/d/eof/04_fake_sentinel.re \
	examples/d/fill/01_fill.re \
	examples/d/fill/02_fill.re \
	examples/d/headers/header.re \
	examples/d/headers/lexer/state.d \
	examples/d/includes/definitions.d \
	examples/d/includes/include.re \
	examples/d/reuse/reuse.re \
	examples/d/reuse/usedir.re \
	examples/d/state/push.re \
	examples/d/submatch/01_stags_fill.re \
	examples/d/submatch/01_stags.re \
	examples/d/submatch/02_mtags.re \
	examples/d/submatch/03_captures.re \
	examples/d/submatch/04_posix_captures.re \
	examples/go/01_basic.go \
	examples/go/01_basic.re \
	examples/go/conditions/parse_u32_blocks.re \
	examples/go/conditions/parse_u32_conditions.re \
	examples/go/encodings/unicode_identifier.re \
	examples/go/eof/01_sentinel.re \
	examples/go/eof/02_bounds_checking.re \
	examples/go/eof/03_eof_rule.re \
	examples/go/eof/04_fake_sentinel.re \
	examples/go/fill/01_fill.re \
	examples/go/fill/02_fill.re \
	examples/go/headers/header.re \
	examples/go/headers/lexer/state.go \
	examples/go/includes/definitions.go \
	examples/go/includes/include.re \
	examples/go/reuse/reuse.re \
	examples/go/reuse/usedir.re \
	examples/go/state/push.re \
	examples/go/submatch/01_stags_fill.re \
	examples/go/submatch/01_stags.re \
	examples/go/submatch/02_mtags.re \
	examples/go/submatch/03_captures.re \
	examples/go/submatch/04_posix_captures.re \
	examples/haskell/01_basic.hs \
	examples/haskell/01_basic.re \
	examples/haskell/conditions/parse_u32_blocks.re \
	examples/haskell/conditions/parse_u32_conditions.re \
	examples/haskell/encodings/unicode_identifier.re \
	examples/haskell/eof/01_sentinel.re \
	examples/haskell/eof/02_bounds_checking.re \
	examples/haskell/eof/03_eof_rule.re \
	examples/haskell/eof/04_fake_sentinel.re \
	examples/haskell/fill/01_fill.re \
	examples/haskell/fill/02_fill.re \
	examples/haskell/headers/header.re \
	examples/haskell/headers/lexer/state.hs \
	examples/haskell/includes/definitions.hs \
	examples/haskell/includes/include.re \
	examples/haskell/reuse/reuse.re \
	examples/haskell/reuse/usedir.re \
	examples/haskell/state/push.re \
	examples/haskell/submatch/01_stags_fill.re \
	examples/haskell/submatch/01_stags.re \
	examples/haskell/submatch/02_mtags.re \
	examples/haskell/submatch/03_captures.re \
	examples/java/01_basic.java \
	examples/java/01_basic.re \
	examples/java/conditions/parse_u32_blocks.re \
	examples/java/conditions/parse_u32_conditions.re \
	examples/java/encodings/unicode_identifier.re \
	examples/java/eof/01_sentinel.re \
	examples/java/eof/02_bounds_checking.re \
	examples/java/eof/03_eof_rule.re \
	examples/java/eof/04_fake_sentinel.re \
	examples/java/fill/01_fill.re \
	examples/java/fill/02_fill.re \
	examples/java/headers/header.re \
	examples/java/headers/lexer/state.java \
	examples/java/includes/definitions.java \
	examples/java/includes/include.re \
	examples/java/reuse/reuse.re \
	examples/java/reuse/usedir.re \
	examples/java/state/push.re \
	examples/java/submatch/01_stags_fill.re \
	examples/java/submatch/01_stags.re \
	examples/java/submatch/02_mtags.re \
	examples/java/submatch/03_captures.re \
	examples/java/submatch/04_posix_captures.re \
	examples/js/01_basic.js \
	examples/js/01_basic.re \
	examples/js/conditions/parse_u32_blocks.re \
	examples/js/conditions/parse_u32_conditions.re \
	examples/js/encodings/unicode_identifier.re \
	examples/js/eof/01_sentinel.re \
	examples/js/eof/02_bounds_checking.re \
	examples/js/eof/03_eof_rule.re \
	examples/js/eof/04_fake_sentinel.re \
	examples/js/fill/01_fill.re \
	examples/js/fill/02_fill.re \
	examples/js/headers/header.re \
	examples/js/headers/lexer/state.js \
	examples/js/includes/definitions.js \
	examples/js/includes/include.re \
	examples/js/reuse/reuse.re \
	examples/js/reuse/usedir.re \
	examples/js/state/push.re \
	examples/js/submatch/01_stags_fill.re \
	examples/js/submatch/01_stags.re \
	examples/js/submatch/02_mtags.re \
	examples/js/submatch/03_captures.re \
	examples/js/submatch/04_posix_captures.re \
	examples/ocaml/01_basic.ml \
	examples/ocaml/01_basic.re \
	examples/ocaml/conditions/parse_u32_blocks.re \
	examples/ocaml/conditions/parse_u32_conditions.re \
	examples/ocaml/encodings/unicode_identifier.re \
	examples/ocaml/eof/01_sentinel.re \
	examples/ocaml/eof/02_bounds_checking.re \
	examples/ocaml/eof/03_eof_rule.re \
	examples/ocaml/eof/04_fake_sentinel.re \
	examples/ocaml/fill/01_fill.re \
	examples/ocaml/fill/02_fill.re \
	examples/ocaml/headers/header.re \
	examples/ocaml/headers/lexer/state.ml \
	examples/ocaml/includes/definitions.ml \
	examples/ocaml/includes/include.re \
	examples/ocaml/reuse/reuse.re \
	examples/ocaml/reuse/usedir.re \
	examples/ocaml/state/push.re \
	examples/ocaml/submatch/01_stags_fill.re \
	examples/ocaml/submatch/01_stags.re \
	examples/ocaml/submatch/02_mtags.re \
	examples/ocaml/submatch/03_captures.re \
	examples/ocaml/submatch/04_posix_captures.re \
	examples/python/01_basic.py \
	examples/python/01_basic.re \
	examples/python/conditions/parse_u32_blocks.re \
	examples/python/conditions/parse_u32_conditions.re \
	examples/python/encodings/unicode_identifier.re \
	examples/python/eof/01_sentinel.re \
	examples/python/eof/02_bounds_checking.re \
	examples/python/eof/03_eof_rule.re \
	examples/python/eof/04_fake_sentinel.re \
	examples/python/fill/01_fill.re \
	examples/python/fill/02_fill.re \
	examples/python/headers/header.re \
	examples/python/headers/lexer/state.py \
	examples/python/includes/definitions.py \
	examples/python/includes/include.re \
	examples/python/reuse/reuse.re \
	examples/python/reuse/usedir.re \
	examples/python/state/push.re \
	examples/python/submatch/01_stags_fill.re \
	examples/python/submatch/01_stags.re \
	examples/python/submatch/02_mtags.re \
	examples/python/submatch/03_captures.re \
	examples/python/submatch/04_posix_captures.re \
	examples/rust/01_basic.re \
	examples/rust/01_basic.rs \
	examples/rust/conditions/parse_u32_blocks.re \
	examples/rust/conditions/parse_u32_conditions.re \
	examples/rust/encodings/unicode_identifier.re \
	examples/rust/eof/01_sentinel.re \
	examples/rust/eof/02_bounds_checking.re \
	examples/rust/eof/03_eof_rule.re \
	examples/rust/eof/04_fake_sentinel.re \
	examples/rust/fill/01_fill.re \
	examples/rust/fill/02_fill.re \
	examples/rust/headers/header.re \
	examples/rust/headers/lexer/state.rs \
	examples/rust/includes/definitions.rs \
	examples/rust/includes/include.re \
	examples/rust/real_world/c.re \
	examples/rust/reuse/reuse.re \
	examples/rust/reuse/usedir.re \
	examples/rust/state/push.re \
	examples/rust/submatch/01_stags_fill.re \
	examples/rust/submatch/01_stags.re \
	examples/rust/submatch/02_mtags.re \
	examples/rust/submatch/03_captures.re \
	examples/rust/submatch/04_posix_captures.re \
	examples/v/01_basic.re \
	examples/v/01_basic.v \
	examples/v/conditions/parse_u32_blocks.re \
	examples/v/conditions/parse_u32_conditions.re \
	examples/v/encodings/unicode_identifier.re \
	examples/v/eof/01_sentinel.re \
	examples/v/eof/02_bounds_checking.re \
	examples/v/eof/03_eof_rule.re \
	examples/v/eof/04_fake_sentinel.re \
	examples/v/fill/01_fill.re \
	examples/v/fill/02_fill.re \
	examples/v/headers/header.re \
	examples/v/headers/lexer/state.v \
	examples/v/includes/definitions.v \
	examples/v/includes/include.re \
	examples/v/reuse/reuse.re \
	examples/v/reuse/usedir.re \
	examples/v/state/push.re \
	examples/v/submatch/01_stags_fill.re \
	examples/v/submatch/01_stags.re \
	examples/v/submatch/02_mtags.re \
	examples/v/submatch/03_captures.re \
	examples/v/submatch/04_posix_captures.re \
	examples/zig/01_basic.re \
	examples/zig/01_basic.zig \
	examples/zig/conditions/parse_u32_blocks.re \
	examples/zig/conditions/parse_u32_conditions.re \
	examples/zig/encodings/unicode_identifier.re \
	examples/zig/eof/01_sentinel.re \
	examples/zig/eof/02_bounds_checking.re \
	examples/zig/eof/03_eof_rule.re \
	examples/zig/eof/04_fake_sentinel.re \
	examples/zig/fill/01_fill.re \
	examples/zig/fill/02_fill.re \
	examples/zig/headers/header.re \
	examples/zig/headers/lexer/state.zig \
	examples/zig/includes/definitions.zig \
	examples/zig/includes/include.re \
	examples/zig/reuse/reuse.re \
	examples/zig/reuse/usedir.re \
	examples/zig/state/push.re \
	examples/zig/submatch/01_stags_fill.re \
	examples/zig/submatch/01_stags.re \
	examples/zig/submatch/02_mtags.re \
	examples/zig/submatch/03_captures.re \
	examples/zig/submatch/04_posix_captures.re

DOCS = doc/re2c.1
HELP = src/msg/help_re2c.cc
if WITH_DLANG
DOCS += doc/re2d.1
HELP += src/msg/help_re2d.cc
endif
if WITH_GOLANG
DOCS += doc/re2go.1
HELP += src/msg/help_re2go.cc
endif
if WITH_HASKELL
DOCS += doc/re2hs.1
HELP += src/msg/help_re2hs.cc
endif
if WITH_JAVA
DOCS += doc/re2java.1
HELP += src/msg/help_re2java.cc
endif
if WITH_JS
DOCS += doc/re2js.1
HELP += src/msg/help_re2js.cc
endif
if WITH_OCAML
DOCS += doc/re2ocaml.1
HELP += src/msg/help_re2ocaml.cc
endif
if WITH_PYTHON
DOCS += doc/re2py.1
HELP += src/msg/help_re2py.cc
endif
if WITH_RUST
DOCS += doc/re2rust.1
HELP += src/msg/help_re2rust.cc
endif
if WITH_VLANG
DOCS += doc/re2v.1
HELP += src/msg/help_re2v.cc
endif
if WITH_ZIG
DOCS += doc/re2zig.1
HELP += src/msg/help_re2zig.cc
endif
BUILT_SOURCES += $(HELP)

man_MANS = $(DOCS)

# include files (stdlib)
dist_stdlib_DATA = \
	include/syntax/c \
	include/syntax/d \
	include/syntax/go \
	include/syntax/haskell \
	include/syntax/java \
	include/syntax/js \
	include/syntax/ocaml \
	include/syntax/python \
	include/syntax/rust \
	include/syntax/v \
	include/syntax/zig \
	include/unicode_categories.re

BAZELFILES := \
	BUILD.bazel \
	WORKSPACE \
	bazel

CMAKEFILES := \
	CMakeLists.txt \
	CMakePresets.json \
	cmake

EXTRA_DIST = \
	$(re2c_BOOT) \
	$(re2c_CUSTOM) \
	$(re2c_SRC_DOC_EXT) \
	$(BAZELFILES) \
	$(CMAKEFILES) \
	BUILD.md \
	CHANGELOG \
	CONTRIBUTING.md \
	IDEAS.md \
	LICENSE \
	MAINTAINERS.md \
	NO_WARRANTY \
	README.md \
	autogen.sh \
	build \
	examples \
	test

CLEANFILES = \
	$(re2c_GEN) \
	$(re2c_GEN_HELP) \
	$(DOCS) \
	$(HELP)

if REBUILD_SYNTAX
STX2CPP = $(top_srcdir)/build/stx2cpp.py
# generate C++ sources from syntax configs and update bootstrap files
.stx.h:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)$(PYTHON) $(STX2CPP) $< $@
	$(AM_V_GEN)cp -f $@ $(top_srcdir)/bootstrap/$@
else
# copy bootstrap files
.stx.h:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)cp $(top_srcdir)/bootstrap/$@ $(@D)
	$(AM_V_at)echo "Reconfigure with --enable-syntax to regenerate $@"
endif

if REBUILD_LEXERS
# generate lexer and update bootstrap files
.re.cc:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)$(RE2C_FOR_BUILD) $(RE2CFLAGS) -o $@ $<
	$(AM_V_GEN)cp $(@:cc=[ch]*) $(top_srcdir)/bootstrap/$(@D)
else
# copy bootstrap files
.re.cc:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)cp $(top_srcdir)/bootstrap/$(@:cc=*) $(@D)
	$(AM_V_at)echo "Reconfigure with --enable-lexers to regenerate $@"
endif

if REBUILD_PARSERS
# generate lexer and update bootstrap files
.ypp.cc:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)$(BISON) --warnings --output=$@ --defines=$(@:cc=h) $<
	$(AM_V_GEN)cp $@ $(@:cc=h) $(top_srcdir)/bootstrap/$(@D)
else
# copy bootstrap files
.ypp.cc:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)cp $(top_srcdir)/bootstrap/$(@:cc=*) $(@D)
	$(AM_V_at)echo "Reconfigure with --enable-parsers to regenerate $@"
endif

# re2c-generated lexer depends on bison-generated parser header (generated by the parser rule)
src/parse/lexer.cc : src/parse/parser.cc
src/parse/conf_lexer.cc : src/parse/conf_parser.cc

# rebuild all re2c sources using newly built re2c
.PHONY: bootstrap
bootstrap: all
	rm $(re2c_GEN)
	$(MAKE) all

.PHONY: docs
if REBUILD_DOCS
RST2TXT = $(top_srcdir)/build/rst2txt.py
RST2MAN = $(top_srcdir)/build/rst2man.py
SPLITMAN = $(top_srcdir)/build/split_man.py
docs: $(DOCS) $(HELP)
$(DOCS) $(HELP) : $(re2c_SRC_DOC_EXT) $(SPLITMAN) $(RST2MAN) $(RST2TXT)
# generate manpage
.rst.1:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)$(PYTHON) $(SPLITMAN) $(top_builddir)/$< $(top_builddir)/$< \
		&& $(PYTHON) $(RST2MAN) --tab-width=4 $(top_builddir)/$< > $@ \
		&& cp $@ $(top_srcdir)/bootstrap/$@
# generate help
.rst.cc:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)$(PYTHON) $(SPLITMAN) $(top_builddir)/$< $(top_builddir)/$< \
		&& $(PYTHON) $(RST2TXT) --variable-name=help $(top_builddir)/$< $@ \
		&& cp $@ $(top_srcdir)/bootstrap/$@
else
docs: $(DOCS) $(HELP)
	$(AM_V_at)echo "Reconfigure with --enable-docs to rebuild docs"
# copy bootstrap manpage
.rst.1:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)cp $(top_srcdir)/bootstrap/$@ $@
# copy bootstrap help
.rst.cc:
	$(AM_V_at)$(MKDIR_P) $(@D)
	$(AM_V_GEN)cp $(top_srcdir)/bootstrap/$@ $@
endif

all-local: docs $(re2c_BOOT_PARSER)

# tests
re2c_TESTSUITE = run_tests.py
.PHONY: tests
tests: all $(re2c_TESTSUITE)
	$(PYTHON) $(top_builddir)/$(re2c_TESTSUITE)
.PHONY: vtests
vtests: all $(re2c_TESTSUITE)
	$(PYTHON) $(top_builddir)/$(re2c_TESTSUITE) --valgrind
.PHONY: wtests
wtests: all $(re2c_TESTSUITE)
	$(PYTHON) $(top_builddir)/$(re2c_TESTSUITE) --wine -j1

re2c_test_list_SOURCES = \
	src/test/list/test.cc

re2c_test_range_SOURCES = \
	src/test/range/test-impl.h \
	src/test/range/test.cc \
	src/test/range/test.h \
	src/util/range.cc \
	src/util/range.h

re2c_test_s_to_n32_unsafe_SOURCES = \
	src/test/s_to_n32_unsafe/test.cc \
	src/util/string_utils.cc

re2c_test_ver_to_vernum_SOURCES = \
	src/test/ver_to_vernum/test.cc \
	src/msg/ver_to_vernum.cc

re2c_test_argsubst_SOURCES = \
	src/test/argsubst/test.cc

check_PROGRAMS = \
	re2c_test_list \
	re2c_test_range \
	re2c_test_s_to_n32_unsafe \
	re2c_test_ver_to_vernum \
	re2c_test_argsubst

TESTS = \
	$(re2c_TESTSUITE) \
	$(check_PROGRAMS)

# benchmarks
if WITH_BENCHMARKS
SUBDIRS += benchmarks/c
EXTRA_DIST += benchmarks/c
endif

# libre2c
if WITH_LIBS
ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES =
include $(top_srcdir)/Makefile.lib.am
endif

# re2d
if WITH_DLANG
bin_PROGRAMS += re2d
re2d_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::D -DRE2C_PROG=\"re2d\"
re2d_SOURCES = $(re2c_SOURCES)
nodist_re2d_SOURCES = $(re2c_GEN) src/msg/help_re2d.cc
endif

# re2go
if WITH_GOLANG
bin_PROGRAMS += re2go
re2go_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::GO -DRE2C_PROG=\"re2go\"
re2go_SOURCES = $(re2c_SOURCES)
nodist_re2go_SOURCES = $(re2c_GEN) src/msg/help_re2go.cc
endif

# re2hs
if WITH_HASKELL
bin_PROGRAMS += re2hs
re2hs_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::HASKELL -DRE2C_PROG=\"re2hs\"
re2hs_SOURCES = $(re2c_SOURCES)
nodist_re2hs_SOURCES = $(re2c_GEN) src/msg/help_re2hs.cc
endif

# re2java
if WITH_JAVA
bin_PROGRAMS += re2java
re2java_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::JAVA -DRE2C_PROG=\"re2java\"
re2java_SOURCES = $(re2c_SOURCES)
nodist_re2java_SOURCES = $(re2c_GEN) src/msg/help_re2java.cc
endif

# re2js
if WITH_JS
bin_PROGRAMS += re2js
re2js_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::JS -DRE2C_PROG=\"re2js\"
re2js_SOURCES = $(re2c_SOURCES)
nodist_re2js_SOURCES = $(re2c_GEN) src/msg/help_re2js.cc
endif

# re2ocaml
if WITH_OCAML
bin_PROGRAMS += re2ocaml
re2ocaml_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::OCAML -DRE2C_PROG=\"re2ocaml\"
re2ocaml_SOURCES = $(re2c_SOURCES)
nodist_re2ocaml_SOURCES = $(re2c_GEN) src/msg/help_re2ocaml.cc
endif

# re2py
if WITH_PYTHON
bin_PROGRAMS += re2py
re2py_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::PYTHON -DRE2C_PROG=\"re2py\"
re2py_SOURCES = $(re2c_SOURCES)
nodist_re2py_SOURCES = $(re2c_GEN) src/msg/help_re2py.cc
endif

# re2rust
if WITH_RUST
bin_PROGRAMS += re2rust
re2rust_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::RUST -DRE2C_PROG=\"re2rust\"
re2rust_SOURCES = $(re2c_SOURCES)
nodist_re2rust_SOURCES = $(re2c_GEN) src/msg/help_re2rust.cc
endif

# re2v
if WITH_VLANG
bin_PROGRAMS += re2v
re2v_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::V -DRE2C_PROG=\"re2v\"
re2v_SOURCES = $(re2c_SOURCES)
nodist_re2v_SOURCES = $(re2c_GEN) src/msg/help_re2v.cc
endif

# re2zig
if WITH_ZIG
bin_PROGRAMS += re2zig
re2zig_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::ZIG -DRE2C_PROG=\"re2zig\"
re2zig_SOURCES = $(re2c_SOURCES)
nodist_re2zig_SOURCES = $(re2c_GEN) src/msg/help_re2zig.cc
endif
